<?php

namespace App\Livewire;

use App\Models\SessionsModel;
use Livewire\Attributes\Computed;
use Livewire\Component;

class SessionsList extends Component
{
    public $server;

    public function mount($server)
    {
        $this->server = $server;
    }

    #[Computed]
    public function sessions()
    {
        return $this->server->sessions()->orderBy('active')->get();
    }

    public function close($sessionId)
    {
        $session = SessionsModel::query()->where('id', '=', $sessionId)->first();
        $session->active = 0;
        $session->end_time = time();
        $session->save();
    }

    public function render()
    {
        return view('livewire.admin.sessions-list');
    }
}
